package com.zcr.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcr.mapper.DruginfoMapper;
import com.zcr.pojo.Druginfo;
import com.zcr.service.DruginfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

@Service("DruginfoServiceimpl")
public class DruginfoServiceimpl implements DruginfoService {

    @Resource
    private DruginfoMapper druginfoMapper;


//    public Page<Druginfo> searchByDrugname(String drugname, @RequestParam(defaultValue = "1") int current, @RequestParam(defaultValue = "4") int size) {
//        QueryWrapper<Druginfo> wrapper=Wrappers.query();
//        wrapper.like(!StringUtils.isBlank(drugname),"drugname",drugname);
//        Page<Druginfo> page=new Page<>(current,size);
//        return druginfoMapper.searchByDrugname(page,wrapper);
//    }


    @Override
    public Page<Druginfo> searchByDrugname(String drugname, Page<Druginfo> page) {
        QueryWrapper<Druginfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isBlank(drugname),"drugname",drugname);
        page=druginfoMapper.selectPage(page,queryWrapper);
        return page;
    }

    @Override
    public void addDruginfo(Druginfo druginfo) {
        druginfoMapper.insert(druginfo);
    }

    @Override
    public void updareDruginfo(Druginfo druginfo) {
//        QueryWrapper<Druginfo> queryWrapper=new QueryWrapper<>();
//        queryWrapper.eq("drugname",druginfo.getDrugname()).eq("changshang",druginfo.getChangshang());
        druginfoMapper.updateById(druginfo);
    }

    @Override
    public void deleteDruginfo(Druginfo druginfo) {
        druginfoMapper.deleteById(druginfo);
    }

    @Override
    public void deleteAllDruginfo(String[] ids) {
        druginfoMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
